from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from datetime import timedelta
from jms.dwd.tab.dwd_tab_reback_transfer_express_base import jms_dwd__dwd_tab_reback_transfer_express_base
from jms.dwd.dwd_terminal_sign_all_detail_new_dt import jms_dwd__dwd_terminal_sign_all_detail_new_dt
jms_dm__dm_deliver_sign_detail_dt = SparkSqlOperator(
    task_id='jms_dm__dm_deliver_sign_detail_dt',
    email=['houwenlong@jtexpress.com'],
    pool_slots=4,
    task_concurrency=1,  # 如果任务不支持并发，则将 task_concurrency 设为 1
    name='jms_dm__dm_deliver_sign_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',  # yarn 任务名称
    sql='jms/dm/dm_deliver_sign_detail_dt/execute.sql',
    driver_memory='4G',
    executor_memory='12G',
    executor_cores=8,
    num_executors=10,
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 20,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 120,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.default.parallelism': 300,
          'spark.sql.shuffle.partitions': 600
          },
    # jars='hdfs:///scheduler/jms/spark/zql/dm_deliver_sign_detail/common-1.0-SNAPSHOT.jar',
    # application='hdfs:///scheduler/jms/spark/zql/dm_deliver_sign_detail/original-jobs-1.0-SNAPSHOT.jar',
    # java_class='com.yunlu.bigdata.jobs.export.DeliverSignDetail',  # spark 主类
    # application_args=['{{ execution_date | cst_ds }}'],  # 参数dt
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 200,
              'hive.exec.max.dynamic.partitions': 200
              },
    execution_timeout=timedelta(minutes=60),
)
# 设置依赖
jms_dm__dm_deliver_sign_detail_dt << [
    jms_dwd__dwd_terminal_sign_all_detail_new_dt,
    jms_dwd__dwd_tab_reback_transfer_express_base
]
